<!DOCTYPE html>
<html class="pixel-ratio-1"><head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>茵曼商城</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="css/sm.min.css">
    <link rel="stylesheet" href="css/sm-extend.min.css">
    <link rel="stylesheet" href="css/inman.css">
    <script src="https://hm.baidu.com/hm.js?5ee51ef74fa865950bb9a2757fdb33ad"></script><script type="text/javascript" src="js/zepto.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/sm.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/sm-extend.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/functions.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/TouchSlide.1.1.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jweixin-1.0.0.js"></script>
    <script>
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?5ee51ef74fa865950bb9a2757fdb33ad";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
    <style type="text/css">.full-html,.full-body{width: 100% !important;height: 100% !important;margin: 0 !important;overflow: hidden !important;}.full-body *{display: none !important;}.full-iframe {display: block !important;}.full-inpage {width: 100% !important;height: 100% !important;margin: 0 !important;overflow: hidden !important;background: rgb(243, 243, 247) !important;}.full-inpage > *:not(.ntalk-mobile-inpage-background) {display: none !important;}</style><script type="text/javascript" async="async" charset="utf-8" src="http://sh-trail.ntalker.com/trail/trail/userinfo.php?action=getregion&amp;siteid=kf_9154&amp;userid=kf_9154_ISME9754_1122715&amp;callback=trail_getregion_E8FDB64B"></script><script type="text/javascript" async="async" charset="utf-8" src="http://dl.ntalker.com/js/xn6/zh_cn.js?siteid=kf_9154&amp;v=nt6.92&amp;t=2017.08.25_011054" data-requiremodule="lang"></script><script type="text/javascript" async="async" charset="utf-8" src="http://dl.ntalker.com/js/xn6/chat.in.js?siteid=kf_9154&amp;v=nt6.92&amp;t=2017.08.25_011054" data-requiremodule="chatManage"></script><script type="text/javascript" async="async" charset="utf-8" src="http://dl.ntalker.com/js/xn6/mqtt31.js?siteid=kf_9154&amp;v=nt6.92&amp;t=2017.08.25_011054" data-requiremodule="MQTT"></script><script type="text/javascript" async="async" charset="utf-8" src="http://dl.ntalker.com/js/xn6/mqtt.chat.js?siteid=kf_9154&amp;v=nt6.92&amp;t=2017.08.25_011054" data-requiremodule="Connection"></script></head>
<body><div class="page-group car-page">
    <div class="page page-current" id="page-1510717438581">
        <!--标题栏-->
        <header class="bar bar-nav">
            <a class="icon icon-left pull-left back" href="javascript:history.go(-1);" data-no-cache="true"></a>
            <a class="icon pull-right" id="empty" style="display:block">清空</a>
            <h1 class="title">购物车</h1>
        </header>
        <!--内容区-->
        <div class="content native-scroll">
            <div class="box1">
                <ul class="cart-list">
                    <li data-price="799.000" data-quantity="1" class="">
                        <div class="w-10">

                            <a href="#" name="checkgoods" data-product_bn="6941919704150"></a>


                            <div class="sellout-cover"></div>
                        </div>
                        <div class="w-30">
                            <a href="http://m.inman.com.cn/index.php/Goods/goodsdetail?goods_bn=1874121020"><img src="http://img.inman.com.cn/uploads/image/20171012/1507781252215871--w_80_h_80.jpg">
                                <div class="sellout-cover"></div>
                            </a>
                            <div class="stock-cover">现货</div>
                        </div>
                        <div class="w-60">
                            <h4>茵曼冬装新款连帽加厚保暖中长款白鸭绒...</h4>
                            <p>颜色：军绿色 / 尺码：S</p>
                            <div class="num" data-product_bn="6941919704150" data-shop_id="0" data-store="4" data-price="799.000" data-shop_store="0">
                                <a href="#" name="jiannum">-</a>
                                <input type="text" value="1" name="cartnum" class="cartnum">
                                <a href="#" name="addnum">+</a>
                                <a href="#" class="cancle-stock" data-product_bn="6941919704150"></a>
                                <div class="cb"></div>
                            </div>
                        </div>
                        <p class="price"><span>￥</span><b>799.00</b></p>
                        <a href="#" class="delete" data-product_bn="6941919704150"></a>
                        <div class="cb"></div>
                    </li>
                </ul>
            </div>

            <!--如果购物车为空 输出box3-->
            <div class="box3" style="display:none;">
                <p>购物车里啥都没有哦~</p>
                <a href="http://m.inman.com.cn/index.php/Home/index">去逛逛</a>
            </div>
        </div>

        <div class="box2">
            <div class="box2-1">
                <a href="#" id="checkall"></a>
                <h5>总金额 <p>￥<span class="total">0</span></p></h5>
            </div>
            <div class="box2-2"><a href="#" id="balance">结 算</a></div>
            <div class="cb"></div>
        </div>
    </div>
    <script>
        $(function(){
            //选择商品
            $('.w-10 a').click(function(){
                var quantity=$(this).parent().parent().attr("data-quantity");
                var price=$(this).parent().parent().attr("data-price");
                var totalprice=$("span.total").text();
                if($(this).is('.on')){
                    $(this).removeClass('on');
                    $("#checkall").removeClass('on');
                    var allprice=parseFloat(totalprice)-parseFloat(quantity*price);
                    $("span.total").text(Number(allprice).toFixed(2));
                }else {
                    $(this).addClass('on');
                    if($("a[name='checkgoods']").length==$("div.w-10 a.on").length){
                        $("#checkall").addClass("on");
                    }
                    allprice=totalprice*1+parseInt(quantity)*price;
                    $("span.total").text(Number(allprice).toFixed(2));
                }
            });

            //选择所有商品
            $('#checkall').click(function(){
                if($(this).is('.on')){
                    $('.w-10 a').removeClass('on');
                    $(this).removeClass('on');
                    $("span.total").text("0");
                }else {
                    $('.cart-list li').each(function(){
                        if(!$(this).is('.sellout')){
                            $(this).children('.w-10').children('a').addClass('on');
                        }
                    });

                    $(this).addClass('on');
                    var  totalPrice=0;
                    for(var n=0;n<$("div.w-10 a.on").length;n++){
                        var price= $("div.w-10 a.on").eq(n).parent().parent().attr("data-price");
                        var quantity=$("div.w-10 a.on").eq(n).parent().parent().attr("data-quantity");
                        totalPrice+=price*parseInt(quantity);
                    }
                    $("span.total").text(Number(totalPrice).toFixed(2));
                }
            });

            //结算订单
            $("#balance").click(function(){
                var rec_id_list = [];
                $("div.w-10 a.on").each(function(){
                    rec_id=$(this).attr('data-product_bn');
                    rec_id_list.push(rec_id);
                });
                if(rec_id_list.length==0){
                    $.toast("请选择结算的商品");
                    return false;
                }
                var url = "http://m.inman.com.cn/index.php/Order/confirm?rec_id_list="+ rec_id_list.join(',');
                location.href = url;
            });


            //点击新增数量
            $("a[name='addnum']").click(function(){
                var cartnum = $(this).parent().find("input[name='cartnum']").val();
                var product_bn = $(this).parent().attr("data-product_bn");
                var shop_id = $(this).parent().attr("data-shop_id");
                var quantity = cartnum*1+1;
                var that = $(this);
                updatenum(product_bn,quantity,shop_id,that,1);
            });

            //点击减少数量
            $("a[name='jiannum']").click(function(){
                var cartnum = $(this).parent().find("input[name='cartnum']").val();
                var product_bn = $(this).parent().attr("data-product_bn");
                var shop_id = $(this).parent().attr("data-shop_id");
                shop_id = shop_id>0 ? shop_id:'';
                var quantity=cartnum*1-1;
                if(quantity==0){
                    return false;
                }
                var that=$(this);
                updatenum(product_bn,quantity,shop_id,that,0);
            });

            //输入数量
            $('.cartnum').change(function(){
                var quantity = $(this).val();
                if(quantity<=0){
                    $.toast('请输入一个有效的值');
                    location.reload();
                    return false;
                }
                var product_bn = $(this).parent().attr("data-product_bn");
                var shop_id = $(this).parent().attr("data-shop_id");
                var that = $(this);
                updatenum(product_bn,quantity,shop_id,that,3);
            });

            function  updatenum(product_bn,quantity,shop_id,that,on){
                var  uri = "http://m.inman.com.cn/index.php/Shopcart/updateProduct";
                $.showIndicator();
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: uri,
                    data: {product_bn: product_bn,quantity:quantity,shop_id:shop_id},
                    async: false,
                    success: function (json) {
                        json = eval('(' + json + ')');
                        if (json.errcode != '1') {
                            $.hideIndicator();
                            $.toast(json.errmsg);
                            if(on=='3'){
                                that.parent().find("input[name='cartnum']").val(1);
                            }
                            return false;
                        }
                        errmsg=on=="1"? "新增成功":"减少成功";
                        newclass=that.parent().parent().parent().find("div.w-10").find("a").attr("class");
                        if(newclass=='on'){
                            on=='1'?  totalPrice=($("span.total").text())*1+(that.parent().attr("data-price"))*1: totalPrice=($("span.total").text())*1-(that.parent().attr("data-price"))*1;
                            $("span.total").text(Number(totalPrice).toFixed(2));
                        }
                        that.parent().find("input[name='cartnum']").val(quantity);
                        that.parent().parent().parent().attr("data-quantity",quantity);
                        $.hideIndicator();
                    }
                })
            }

            //取消现货购买
            $(".cancle-stock").click(function(){
                var product_bn=$(this).attr("data-product_bn");
                var uri = "http://m.inman.com.cn/index.php/Shopcart/cancelOffline";
                $.showIndicator();
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: uri,
                    data: {product_bn: product_bn},
                    async: false,
                    success: function (json) {
                        $.hideIndicator();
                        json = eval('(' + json + ')');
                        if (json.errcode != '1') {
                            $.toast(json.errmsg);
                            return false;
                        }
                        $.toast(json.errmsg);
                        if (json.errcode && json.url !=='') {
                            setTimeout(function() {
                                window.location.href =json.url;
                            }, 200);
                        } else {
                            return false;
                        }
                    }
                })
            });

            //删除商品
            $('.delete').click(function(){
                var product_bn=$(this).attr("data-product_bn");
                var that=$(this);
                var buttons1 = [
                    {
                        text: '确定将所选商品移出购物车吗?',
                        label: true
                    },
                    {
                        text: '确定',
                        bold: true,
                        onClick: function() {
                            uri = "http://m.inman.com.cn/index.php/Shopcart/deleteshopcart";
                            $.ajax({
                                cache: true,
                                type: "POST",
                                url: uri,
                                data: {product_bn: product_bn},
                                async: false,
                                success: function (json) {
                                    json = eval('(' + json + ')');
                                    if (json.errcode != '1') {
                                        $.toast(json.errmsg);
                                        return false;
                                    }
                                    if(that.parent().find("div.w-10 a").attr("class")=='on'){
                                        var price=that.parent().attr('data-price');
                                        var quantity=that.parent().attr('data-quantity');
                                        var totalPrice=($("span.total").text())*1-price*quantity;
                                        $("span.total").text(Number(totalPrice).toFixed(2));
                                    }
                                    $.toast(json.errmsg);
                                    that.parent().remove();
                                    var num=$("div.box1 ul li").length;
                                    if(num<1){
                                        $("div.box1").hide();
                                        $("div.box2").hide();
                                        $("div.box3").show();
                                    }
                                    location.reload();
                                }
                            })
                        }
                    }
                ];
                var buttons2 = [
                    {
                        text: '取消',
                        bg: 'danger'
                    }
                ];
                var groups = [buttons1, buttons2];
                $.actions(groups);
            });

            //清空购物车
            $('#empty').click(function(){
                var num=$("div.box1 ul li").length;
                if(num<1){ return false; }
                var buttons1 = [
                    {
                        text: '确定清空购物车吗?',
                        label: true
                    },
                    {
                        text: '确定',
                        bold: true,
                        onClick: function() {
                            //do ajax
                            uri = "http://m.inman.com.cn/index.php/Shopcart/deleteAllcart";
                            $.ajax({
                                cache: true,
                                type: "POST",
                                url: uri,
                                data:{},
                                async: false,
                                success: function (json) {
                                    json = eval('(' + json + ')');
                                    if (json.errcode != '1') {
                                        $.toast(json.errmsg);
                                        return false;
                                    }
                                    $.toast(json.errmsg);
                                    $("div.box1").hide();
                                    $("div.box2").hide();
                                    $("div.box3").show();
                                    location.reload();
                                }
                            })
                        }
                    }
                ];
                var buttons2 = [
                    {
                        text: '取消',
                        bg: 'danger'
                    }
                ];
                var groups = [buttons1, buttons2];
                $.actions(groups);
            });
        });
        $.init();
    </script>
</div><div id="nTalk_post_hiddenElement" style="left: -10px; top: -10px; visibility: hidden; display: none; width: 1px; height: 1px;"></div>



</body></html>